package com.jbp.controller;

import com.jbp.model.GiftShop;
import com.jbp.service.GiftShopService;
import com.jbp.service.WalletRecordService;
import com.jbp.utils.R;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 商城礼物(GiftShop)表控制层
 * @author cc
 * @since 2020-06-20 08:53:26
 */
@Api(tags ="APP接口-房间-商店礼物" ,hidden = true)
@ApiIgnore
@RestController
@RequestMapping("/rest/giftShop")
public class GiftShopController {
    @Autowired
    private GiftShopService giftShopService;

    @Autowired
    private WalletRecordService walletRecordService;

    /** 列表 */
    @ApiOperation(value="商店礼物列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = GiftShop.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/list")
    public R list(){
        return R.ok(giftShopService.allGift());
    }

    /** 商店送礼 */
    @ApiOperation(value="商店送礼")
    @ApiResponses({
        @ApiResponse(code = 200,message = "成功",response = Void.class),
        @ApiResponse(code = 201,message = "返回失败信息")
    })
    @ApiImplicitParams({
        @ApiImplicitParam(name = "roomId",value = "房间Id", paramType = "body"),
        @ApiImplicitParam(name = "giftId",value = "礼物Id", paramType = "body"),
        @ApiImplicitParam(name = "otherId",value = "多个userId用逗号,连接", paramType = "body"),
        @ApiImplicitParam(name = "num",value = "礼物数量", paramType = "body"),
    })
    @PostMapping("/sendShopGift")
    public synchronized R sendShopGift(@RequestBody Map<String, Object> params, @RequestAttribute("userId") Integer userId){
        if (params.get("roomId")==null || params.get("roomId").equals("")
            || params.get("giftId")==null || params.get("giftId").equals("")
                || params.get("otherId")==null || params.get("otherId").equals("")) {
            return R.error("参数异常");
        }
        params.put("userId",userId);
        giftShopService.sendShopGift(params);
        return R.ok();
    }


    /**
     * 用户送出礼物超过100心钻，可以看到抽奖游戏
     * @param userId
     * @return
     */
    @GetMapping("/showGame")
    public R showGame(@RequestAttribute("userId") Integer userId){
        BigDecimal total = walletRecordService.getChangeBalance(userId);
        if (total != null && total.compareTo(new BigDecimal(99)) > 0) {
            return R.ok().put("data", "yes");
        }else  {
            return R.ok().put("data", "no");
        }

    }


}